package com.shuzixiangcun.controller.admin;

import com.github.pagehelper.PageInfo;
import com.shuzixiangcun.entity.JobPostings;
import com.shuzixiangcun.entity.Members;
import com.shuzixiangcun.service.admin.MembersServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 成员信息表(Members)表控制层
 *
 * @author makejava
 * @since 2024-07-02 17:39:43
 */
@RestController
@RequestMapping("admin/members")
public class MembersController {
    /**
     * 服务对象
     */
    @Resource
    private MembersServiceImpl membersService;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Members> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.membersService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param members 实体
     * @return 新增结果
     */
    @PostMapping("addMembers")
    public ResponseEntity<Members> add(Members members) {
        return ResponseEntity.ok(this.membersService.insert(members));
    }

    /**
     * 编辑数据
     *
     * @param members 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Members> edit(Members members) {
        return ResponseEntity.ok(this.membersService.update(members));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/deleteById")
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.membersService.deleteById(id));
    }


    @GetMapping("queryListByUserId")
    public ResponseEntity<List<Members>> queryListByUserId(Integer userId) {
        Integer id=userId;
        return ResponseEntity.ok(this.membersService.getMembers(id,userId));
    }

    @GetMapping("/PageInfo")
    public ResponseEntity<PageInfo<Members>> getJobPostingsList(@RequestParam Integer pageNo, @RequestParam Integer pageSize){

        return ResponseEntity.ok(this.membersService.getPageInfo(pageNo,pageSize));
    }

    @PostMapping("updateByState")
    public ResponseEntity updateByState(Members members){
        String state1=members.getState().equals("Y")?"N":"Y";

        members.setState(state1);
        if (this.membersService.updateByState(members)>0){
            return ResponseEntity.status(200).header("Custom-Header", "foo")
                    .body("修改成功");
        }
        return ResponseEntity.status(500).header("Custom-Header", "foo")
                .body("修改失败");
    }

}

